package com.example.beson.androiddemo.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.beson.androiddemo.utils.CardAdapter;
import com.example.beson.androiddemo.R;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * Created by 史国院 on 2017/4/18.
 * Desc ******
 */

public class JavaFragment extends Fragment {
//    @BindView(R.id.fragment_swiperefresh)
//    SwipeRefreshLayout fragment_swiperefresh;
    @BindView(R.id.fragment_recyclerview)
    RecyclerView fragmentRecyclerview;
    Unbinder unbinder;
    private CardAdapter cardAadpter;
    private List<String> list=new ArrayList<>();
    private int lastVisibleItem;
    private GridLayoutManager gridManager;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_layout, container, false);
        unbinder = ButterKnife.bind(this, view);
        initData();
        return view;
    }

    private void initData() {
//        fragment_swiperefresh.setColorSchemeColors(getResources().getColor(R.color.colorPrimary));
        /**
         * recyclerView
         */
        for(int i=0;i<20;i++){
            list.add("Java  "+i);
        }
        gridManager=new GridLayoutManager(getActivity(),2);
        fragmentRecyclerview.setItemAnimator(new DefaultItemAnimator());
        fragmentRecyclerview.setLayoutManager(gridManager);
        cardAadpter=new CardAdapter(list,getActivity());
        fragmentRecyclerview.setAdapter(cardAadpter);
//        fragment_swiperefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
//            @Override
//            public void onRefresh() {
//                new Handler().postDelayed(new Runnable() {
//                    @Override
//                    public void run() {
//                        fragment_swiperefresh.setRefreshing(false);
//                    }
//                },2000);
//            }
//        });
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }
}
